$("#activitySubmit").click(function(){
	
	if(validateRes()){
		var userMobile = $("#input_username").val();
		var yzCode = $("#input_yz").val();
		var pwd = $("#input_password").val();
		
		if(pwd.length < 6 || pwd.length > 20){
			layer.msg("请设置密码长度为6-20位");
			return false;
		}
		if(!isPoneAvailable(userMobile)){
			layer.msg("手机号格式不正确");
			return false;
		}
		$.ajax({
			url:g_requestContextPath+"/activity/doRegist",
			type:"post",
			data:{
				"mobile":userMobile,
				"password":encryptionPwd(pwd),
				"code":yzCode,
				"referrerMoblie":$("#input_referee").val()
			},
			success:function(data){
				//console.log(data);
				if("infoCodeWrong" == data){
					layer.msg('请输入正确的验证码');
				}else if("wrongmobile" == data){
					layer.msg('请输入正确的手机号');
				}else if(1 == toJson(data).result.status){
					$("#activitySubmit").html('注册中...');
					window.location.href = g_requestContextPath + "/login";
				}else{
					layer.msg(toJson(data).result.errorMessage);
				}
			}
		});
	}
});

/**
 * 非空验证
 * @returns
 */
function validateRes(){
	var userMobile = $("#input_username").val();
	var yzCode = $("#input_yz").val();
	var pwd = $("#input_password").val();
	var result = true;
	if($.trim(pwd).length == 0){
		layer.msg("请输入密码");
		result = false;
	}
	if($.trim(yzCode).length == 0){
		layer.msg("请输入验证码");
		result = false;
	}
	if($.trim(userMobile).length == 0){
		layer.msg("请输入手机号");
		result = false;
	}
	return result;
}
/**
 * 发送验证码
 * @returns
 */
$("#yzphone").click(function(){
	var userMobile = $("#input_username").val();
	if($.trim(userMobile).length == 0){
		layer.msg("手机号不能为空");
		return false;
	}else if(!isPoneAvailable(userMobile)){
		layer.msg("手机号格式不正确");
		return false;
	}
	
	$.post(g_requestContextPath + "/user/checkMobile",{"mobile":userMobile},function(data){
		if("userExist" == data){
			layer.msg("该手机号已注册，请登录");
			return false;
		}else{
			$.ajax({
				url:g_requestContextPath + "/user/sendMsgForRegister",
				type:"post",
				dataType:"json",
				data:{"mobile":userMobile},
				success:function(data){
					if("success" == data.result){
						layer.msg("短信发送成功，请注意查收");
						var t = 60;
						$("#yzphone").html(t + 's');
						var obj = $("#yzphone");
						obj.attr("disabled", "true");
						var interval = setInterval(function() {
							if (1 == t) {
								obj.removeAttr("disabled");
								obj.html('发送验证码');
								clearInterval(interval);
							} else {
								obj.html(--t + 's');
							}
						}, 1000);
					}else{
						if("null" != data.result){
    	    				layer.msg(data.result);
    	    			}else{
    	    				layer.msg("短信发送失败，请稍后重试");
    	    			}
					}
				}
			});
		}
	});
});